<?php
//author: liuchenguang
//功能:评论管理
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Session;
use app\index\model\Comment as DynamicComment;
use app\index\model\Message;
use app\index\model\Dynamic;


class Comment extends Controller{
	
	//显示评论
	//param 表名
	//param 动态ID
	public function displaycomment(){
		//根据动态ID查找评论内容
		$list=DynamicComment::paginate(5);
		$this->assign('list',$list);
		$this->assign('count',count($list));
		//返回评论页面
		return view('comment');
	}
	
	//添加评论
	//param 动态ID
	//param 评论人ID
	//param 内容
	//param 时间
	//return 
	//"0" 成功 添加通知私信。。。
	//"1" 错误
	public function addcomment(Request $request){
		//添加评论
		$dycomment = new DynamicComment;
		$dycomment->comment_id = 4;
		//$dycomment->sender_id=Session::get('user_id');
		$dycomment->sender_id=3;
		$dycomment->dynamic_id=$request->param("dynamic_id");
		$dycomment->content=$request->param("content");
		$dycomment->time=date('Y-m-d');
		if($dycomment->save()){
		//根据动态id获取动态作者id
		$dy = Dynamic::get('$request->param("dynamic_id")');
		//添加私信 告诉动态作者有新回复
		$Msg = new Message;
		$Msg->topic_id = 0;
		$Msg->topic="系统通知";
		$Msg->time=data('Y-m-d');
		$Msg->receiver_id=$dy['user_id'];
		//$Msg->content=Session::get('user_name').'评论了你的动态！';
		$Msg->content='某某某回复了你的评论！';
		$Msg->is_read=false;
		$Msg->msg_id=100;
		$Msg->save();
			return json("0");
		}
		else{
			return json("1");
		}
	}
	
	//回复评论
	//param 动态ID
	//param 评论人ID
	//param 被回复评论人ID
	//param 内容
	//param 时间
	//return 
	//"0" 成功
	//"1" 错误
	public function replycomment(Request $request){
		//添加评论
		$dycomment = new DynamicComment;
		$dycomment->comment_id = 14;
		//$dycomment->sender_id=Session::get('user_id');
		$dycomment->sender_id=3;
		$dycomment->receiver_id=$request->param("receiver_id");
		$dycomment->dynamic_id=$request->param("dynamic_id");
		$dycomment->content=$request->param("content");
		$dycomment->time=date('Y-m-d');
		if($dycomment->save()){
		//添加私信 告诉评论作者有回复
		$Msg = new Message;
		$Msg->topic_id = 0;
		$Msg->topic="系统通知";
		$Msg->time=date('Y-m-d');
		$Msg->receiver_id=$request->param("receiver_id");
		//$Msg->content=Session::get('user_name').'回复了你的评论！';
		$Msg->content='某某某回复了你的评论！';
		$Msg->is_read=false;
		$Msg->msg_id=100;
		$Msg->save();
			return json("0");
		}
		else{
			return json("1");
		}
	}

	//查找评论
	//param 动态ID
	//"0" 成功
	//"1" 错误
	public function searchcommnet(){
		
	}
	
}


?>